﻿
using Dapper;
using HBase;
using HBase.db;
using System;
using System.Data;
using System.Reflection.Emit;
namespace hCommand 
{
    //一个任务完成则不允许执行删除任务
    public class StockMoveEngine<CS> : GkTransaction where CS : AbsCoreStock {

        public  long id;
        public int des;
        protected CS cs = null;
        //入库完成反馈
        protected override TransRes Execute()
        { 
              cs = getById<CS>(  id);
            if (cs == null) { 
                return new TransRes(id + "托盘不存在!"); 
            }
            if (cs.status != (int)StockStatus.空闲) {
                return new TransRes(id + "托盘移动中!");
            }

          
            String sql1 = "update Core_stock set loc_id=@des ,change_Time=sgj_get_sys_now   where id=@stockId ";
            exec(sql1, new { stockId = cs.id, des }); 
            updateLoc(des);
            updateLoc(cs.locId); 
            afterCSMove();
            return new TransRes();
        }
       void updateLoc(long id) {
            int count = queryUnique<int>("select count(*) from  Core_stock where loc_id=@id   ", new { id });
            exec("update core_wh_loc  set Count_stock=@count  where id=@id", new { count, id });
        }
        protected virtual void afterCSMove() { 
        
        }


    }
}
